home *** CD-ROM | disk | FTP | other *** search
- { pgraph.pas -- Print graphics }
-
- program PGraph;
-
- {$R pgraph.res}
-
- uses WinTypes, WinProcs, WObjects, UPrint;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_New = 101; { Menu:New command ID }
- cm_Print = 102; { Menu:Print command ID }
- cm_Quit = 103; { Menu:Exit command ID }
- numShapes = 10; { Number of ellipses, rectangles, and lines }
-
- type
-
- ShapeArray = array[1 .. numShapes] of TRect;
-
- PGraphApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PPGraphWindow = ^PGraphWindow;
- PGraphWindow = object(TWindow)
- ClientWidth, ClientHeight: Word;
- Ellipses, Rectangles, Lines: ShapeArray;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure SetupWindow; virtual;
- procedure MakeRandShapes(var Shapes: ShapeArray);
- procedure MakeShapes;
- procedure DrawShapes(DC: HDC);
- procedure Paint(PaintDC: HDC;
- var PaintInfo: TPaintStruct); virtual;
- procedure CMNew(var Msg: TMessage);
- virtual cm_First + cm_New;
- procedure CMPrint(var Msg: TMessage);
- virtual cm_First + cm_Print;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- end;
-
-
- { PGraphApplication }
-
- {- Initialize PGraphApplication object's window }
- procedure PGraphApplication.InitMainWindow;
- begin
- MainWindow := New(PPGraphWindow, Init(nil, 'PGraph'))
- end;
-
-
- { PGraphWindow }
-
- {- Construct PGraphWindow object }
- constructor PGraphWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- with Attr do
- begin
- X := 10; Y := 10; W := 500; H := 300;
- Menu := LoadMenu(HInstance, PChar(id_Menu))
- end
- end;
-
- {- Prepare window contents. }
- procedure PGraphWindow.SetupWindow;
- begin
- TWindow.SetupWindow;
- MakeShapes
- end;
-
- {- Fill Shapes array with random values }
- procedure PGraphWindow.MakeRandShapes(var Shapes: ShapeArray);
- var
- I: Integer;
- R: TRect;
- begin
- GetClientRect(HWindow, R);
- ClientWidth := R.Right;
- ClientHeight := R.Bottom;
- for I := 1 to numShapes do
- with Shapes[I] do
- begin
- Left := Random(ClientWidth div 2);
- Top := Random(ClientHeight div 2);
- Right := Left + Random(ClientWidth - Left);
- Bottom := Top + Random(ClientHeight - Top)
- end
- end;
-
- {- Create a few shapes at random }
- procedure PGraphWindow.MakeShapes;
- begin
- MakeRandShapes(Ellipses);
- MakeRandShapes(Rectangles);
- MakeRandShapes(Lines)
- end;
-
- {- Draw shapes into device context (display or printer) }
- procedure PGraphWindow.DrawShapes(DC: HDC);
- var
- I: Integer;
- begin
- for I := 1 to numShapes do
- begin
- with Ellipses[I] do
- Ellipse(DC, Left, Top, Right, Bottom);
- with Rectangles[I] do
- Rectangle(DC, Left, Top, Right, Bottom);
- with Lines[I] do
- begin
- MoveTo(DC, Left, Top);
- LineTo(DC, Right, Bottom)
- end
- end
- end;
-
- {- Paint shapes inside window }
- procedure PGraphWindow.Paint(PaintDC: HDC;
- var PaintInfo: TPaintStruct);
- begin
- TWindow.Paint(PaintDC, PaintInfo);
- DrawShapes(PaintDC)
- end;
-
- {- Execute Menu:New shapes command }
- procedure PGraphWindow.CMNew(var Msg: TMessage);
- begin
- MakeShapes;
- InvalidateRect(HWindow, nil, true)
- end;
-
- {- Execute Menu:Print shapes command }
- procedure PGraphWindow.CMPrint(var Msg: TMessage);
- begin
- if PrnStart('PGraph') then
- begin
- DrawShapes(PDc);
- NewPage;
- PrnStop
- end
- end;
-
- {- Execute Menu:Exit command }
- procedure PGraphWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- var
-
- PGraphApp: PGraphApplication;
-
- begin
- PGraphApp.Init('PGraphApp');
- PGraphApp.Run;
- PGraphApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/17/1991
- ---------------------------------------------------------------}
-